package prj5;

import student.TestCase;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;

/**
 * Test DataProcessing class.
 * @author xinruili
 * @version 1.0
 */
public class DataProcessingTest extends TestCase {
    private DataProcessing dataProcessing;

    /**
     * sets up any needed variables for test methods.
     * @throws Exception sets up variables
     * @author xinruili
     * @version 1.0
     */
    @Override
    public void setUp() throws Exception {
        super.setUp();
        dataProcessing = new DataProcessing(
                "Cases_and_Deaths_by_race_CRDT_Sep2020.csv");
    }

    /**
     * testGetStatesData.
     */
    public void testGetStatesData() {
        List<Data> dataList = dataProcessing.getStates();
        for (Data data:dataList) {
            System.out.println(data.getStateName());
            data.showSout();
        }
        String fileName = "CovidOutput_1.txt";
        String covidOutput1 = "";
        Scanner fileData = null;
        try {
            // Can throw FileNotFoundException
            fileData = new Scanner(new File(fileName));
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        while (fileData.hasNextLine()) {
            covidOutput1 += fileData.nextLine() + "\n";
        }
        assertFuzzyEquals("Output not"
                        + " as expected for input file "
                        + "Cases_and_Deaths_by_race"
                        + "_CRDT_Sep2020.csv",
                covidOutput1, systemOut().getHistory());
    }

    /**
     * test ToString.
     */
    public void testToString() {
        assertEquals("DataProcessing{"
                + "raceNames=[white, "
                + "black, latinx, asian, other], raceNumber=5}",
                dataProcessing.toString());
    }

    /**
     * test GetStates.
     */
    public void testGetStates() {
        List<Data> datas = dataProcessing.getStates();
        assertEquals(datas, dataProcessing.getStates());
    }
}
